package com.joinval.common.utils;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;


import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author zhizuntop
 * @create 2025/2/11 16:54
 */
public class DateExcelConverter implements Converter<Date> {

    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

    @Override
    public Class<Date> supportJavaTypeKey() {
        return Date.class;
    }
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public WriteCellData convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if (value == null) {
            return new WriteCellData();
        }
        return new WriteCellData(DATE_FORMAT.format(value));
    }
}
